//
//  JieSuanView.m
//  ShangChengMoBan
//
//  Created by 张铁军 on 16/8/24.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "JieSuanView.h"
#import "WXApi.h"

@implementation JieSuanView{

float _height;
UIButton *_cleanBtn;
UIView *_backView;
UIView *_bottomView;
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _height = 70 * _kscH;
        [self initView];
    }
    return self;
}

-(void)initView{
    self.backgroundColor = [UIColor clearColor];
    self.hidden = YES;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, self.height)];
    _backView.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    [self addSubview:_backView];
    
    _bottomView = [[UIView alloc]init];
    _bottomView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_bottomView];
    
    NSArray * zhiFuFangShiAry ;
    
    if([WXApi isWXAppInstalled]){//检测是否安装微信
        
        zhiFuFangShiAry = @[@"余额支付",@"支付宝支付",@"微信支付"];
        _height = 50 *_kscH;
        _bottomView.frame = CGRectMake(0, self.height, KScreenWidth, 140 + 50 * _kscH);
    }else{
        zhiFuFangShiAry = @[@"余额支付",@"支付宝支付"];
        _height = 70 *_kscH;
        _bottomView.frame = CGRectMake(0, self.height, KScreenWidth, 140 + 70 * _kscH);
    }
    
    NSArray *tuBiaoAry = @[@"余额支付",@"支付宝(1)",@"微信(1)"];
    
    
    _jELabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, KScreenWidth - 20, 30)];
    _jELabel.textAlignment = NSTextAlignmentRight;
    _jELabel.font = [UIFont systemFontOfSize:19];
    _jELabel.textColor = ZONGCOLOR;
    _jELabel.text = @"%99.00";
    [_bottomView addSubview:_jELabel];
    
    UILabel *fenGe = [[UILabel alloc]initWithFrame:CGRectMake(0, _jELabel.bottom + 9, KScreenWidth, 1)];
    fenGe.backgroundColor = LIGHTGRAYBACKCOLOR;
    [_bottomView addSubview:fenGe];
    
    //    _yuEView = [[YEShiYongView alloc]initWithFrame:CGRectMake(0, _jELabel.bottom + 10, KreenWidth, 50)];
    
    //    [_bottomView addSubview:_yuEView];
    
    //    UILabel *zhiFuTypeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, _yuEView.bottom, KreenWidth, 40)];
    //    zhiFuTypeLabel.textColor = [UIColor lightGrayColor];
    //    zhiFuTypeLabel.font = [UIFont systemFontOfSize:19];
    //    zhiFuTypeLabel.text = @"支付方式";
    //    zhiFuTypeLabel.textAlignment = NSTextAlignmentCenter;
    //    [_bottomView addSubview:zhiFuTypeLabel];
    
    for (int i= 0; i < zhiFuFangShiAry.count; i++) {
        float floatX =  (KScreenWidth - zhiFuFangShiAry.count * _height )/(zhiFuFangShiAry.count+1);
        UIButton *zhiFuFangShiBtn = [[UIButton alloc]initWithFrame:CGRectMake( floatX + (_height  + floatX) * i, _jELabel.bottom + 30, _height, _height)];
        [self addSubview:zhiFuFangShiBtn];
        [zhiFuFangShiBtn addTarget:self.delegate action:@selector(huaFeiZFTypeChose:) forControlEvents:UIControlEventTouchUpInside];
        zhiFuFangShiBtn.tag = i;
        
        [zhiFuFangShiBtn setImage:[UIImage imageNamed:[tuBiaoAry objectAtIndex:i]] forState:UIControlStateNormal];
        //        [_btnAry addObject:zhiFuFangShiBtn];
        [_bottomView addSubview:zhiFuFangShiBtn];
    }
    
    _cleanBtn = [[UIButton alloc]initWithFrame:CGRectMake( 40, _bottomView.height - 50, _bottomView.width - 80, 40)];
    [_cleanBtn setTitle:@"取消" forState:UIControlStateNormal];
    _cleanBtn.backgroundColor = ZONGCOLOR;
    _cleanBtn.layer.cornerRadius = 20;
    _cleanBtn.titleLabel.font = [UIFont systemFontOfSize:18 weight:2];
    
    [_cleanBtn addTarget:self.delegate action:@selector(clearBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [_bottomView addSubview:_cleanBtn];
}

-(void)show{
    self.hidden = NO;
    _backView.hidden = NO;
    [UIView animateWithDuration:0.5 animations:^{
        _bottomView.frame = CGRectMake(0, self.height - _bottomView.height, self.width,_bottomView.height);
    }];
}
-(void)viewHidden{
    
    [UIView animateWithDuration:0.5 animations:^{
        //        [self.yuEView.mySwith setOn:NO];//恢复没有使用优惠状态,方便算价钱
        _bottomView.frame = CGRectMake(0, self.height , self.width,_bottomView.height);
        _backView.hidden = YES;
        self.hidden = YES;
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
